package com.cssw.fyzb.tps.service.im;

import com.cssw.fyzb.tps.service.im.common.ImHttpComm;
import com.cssw.fyzb.tps.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author Jian Qin.
 */
@Service
public class MessageServiceImpl implements MessageService{
    @Autowired
    private ImHttpComm imHttpComm;

    @Override
    public ImHttpComm.ImResult sendMsg(String str) {
        return imHttpComm.post("/openim/sendmsg", str);
    }

    @Override
    public ImHttpComm.ImResult batchSendMsg(String str) {
        return imHttpComm.post("/openim/batchsendmsg", str);
    }

    @Override
    public ImHttpComm.ImResult importMsg(String toString) {
        return null;
    }

    @Override
    public ImHttpComm.ImResult getRoamMsg(String fromAccount, String toAccount, long maxCnt, long minTime, long maxTime, String lastMsgKey) {
        Map<String, Object> params = new HashMap<>();
        params.put("From_Account", fromAccount);
        params.put("To_Account", toAccount);
        params.put("MaxCnt", maxCnt);
        params.put("MinTime", minTime);
        params.put("MaxTime", maxTime);
        if(!StringUtil.isBlank(lastMsgKey)){
            params.put("LastMsgKey", lastMsgKey);
        }
        return imHttpComm.post("/openim/admin_getroammsg", params);
    }

    @Override
    public ImHttpComm.ImResult msgWithDraw(String from_account, String to_account, String msgKey) {
        Map<String, Object> params = new HashMap<>();
        params.put("From_Account", from_account);
        params.put("To_Account", to_account);
        params.put("MsgKey", msgKey);
        return imHttpComm.post("/openim/admin_msgwithdraw", params);
    }

    @Override
    public ImHttpComm.ImResult setMsgRead(String report_account, String peer_account) {
        Map<String, Object> params = new HashMap<>();
        params.put("Report_Account", report_account);
        params.put("Peer_Account", peer_account);
        return imHttpComm.post("/openim/admin_set_msg_read", params);
    }

    @Override
    public ImHttpComm.ImResult sendGroupMsg(String toJson) {
        return imHttpComm.post("/group_open_http_svc/send_group_msg", toJson);
    }
}
